﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace DBLibiary
{
    public class SqlDBOperater : IDBOperater
    {
        private string _ConnectionString;
        private SqlConnection _SqlConnection;
        private object _lockObject = new object();
        private DbTransaction _SqlTransaction;

        #region IDBOperater 成员

        public DBConnConfig A_DBConnConfig { get; set; }
        public string A_ConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_ConnectionString))
                {
                    string defaultConnString = "Data Source=#IP#,#PROT#\\#EXPRESSNAME#;Initial Catalog=#DATABASENAME#;User ID=#USERID#;Password=#PASSWORD#;Connect Timeout=60";
                    defaultConnString = defaultConnString.Replace("#IP#", A_DBConnConfig.ServerIP);
                    defaultConnString = defaultConnString.Replace("#PROT#", A_DBConnConfig.Port);
                    defaultConnString = defaultConnString.Replace("#DATABASENAME#", A_DBConnConfig.DataBase);
                    defaultConnString = defaultConnString.Replace("#EXPRESSNAME#", A_DBConnConfig.SqlExpressName);
                    defaultConnString = defaultConnString.Replace("#USERID#", A_DBConnConfig.UserId);
                    defaultConnString = defaultConnString.Replace("#PASSWORD#", A_DBConnConfig.PassWord);
                    _ConnectionString = defaultConnString;
                }
                return _ConnectionString;
            }
        }

        public DbConnection A_DbConnection
        {
            get
            {
                lock (_lockObject)
                {
                    if (_SqlConnection == null)
                    {

                        _SqlConnection = new SqlConnection(A_ConnectionString);
                    }
                }
                return _SqlConnection;
            }
        }

        public DbTransaction A_DbTransaction
        {
            get { return _SqlTransaction; }
            set { _SqlTransaction = value; }
        }

        public void OpenConnection()
        {
            if (A_DbConnection.State != ConnectionState.Open)
                A_DbConnection.Open();
        }

        public void CloseConnection()
        {
            if (A_DbConnection.State != ConnectionState.Closed)
                A_DbConnection.Close();
        }

        public void BeginTransaction()
        {
            if (A_DbTransaction == null)
            {
                OpenConnection();
                A_DbTransaction = A_DbConnection.BeginTransaction();
            }
            else
            {
                
            }
        }

        public void CommitTransaction()
        {
            throw new NotImplementedException();
        }

        public void RollbackTransaction()
        {
            throw new NotImplementedException();
        }

        public System.Data.IDataParameter CreateParameter(string strParaName, object objParaValue, System.Data.DbType Dbtype)
        {
            throw new NotImplementedException();
        }

        public System.Data.IDataParameter CreateParameter(string strParaName, object objParaValue, System.Data.DbType Dbtype, int intParaSize)
        {
            throw new NotImplementedException();
        }

        public System.Data.IDataParameter CreateParameter(string strParaName, object objParaValue, System.Data.DbType Dbtype, System.Data.ParameterDirection Paradirect)
        {
            throw new NotImplementedException();
        }

        public System.Data.IDataParameter CreateParameter(string strParaName, object objParaValue, System.Data.DbType Dbtype, int intParaSize, System.Data.ParameterDirection Paradirect)
        {
            throw new NotImplementedException();
        }

        public System.Data.IDataParameter CreateParameter(string strParaName, object objParaValue, System.Data.DbType Dbtype, int intPrecision, int intScale, System.Data.ParameterDirection Paradirect)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet ExecuteSqlForDataSet(string strSQL)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet ExecuteSqlForDataSet(string strSQL, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataTable ExecuteSqlForDataTable(string strSQL)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataTable ExecuteSqlForDataTable(string strSQL, string dataTableName)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataTable ExecuteSqlForDataTable(string strSQL, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataTable ExecuteSqlForDataTable(string strSQL, string dataTableName, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        public object ExecuteSqlScalarForObject(string sql)
        {
            throw new NotImplementedException();
        }

        public object ExecuteSqlScalarForObject(string sql, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet ExecuteProcForDataSet(string strSQL)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet ExecuteProcForDataSet(string strSQL, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataTable ExecuteProcForDataTable(string strSQL)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataTable ExecuteProcForDataTable(string strSQL, string dataTableName)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataTable ExecuteProcForDataTable(string strSQL, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataTable ExecuteProcForDataTable(string strSQL, string dataTableName, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        public int ExecuteSqlNonQuery(string strSQL)
        {
            throw new NotImplementedException();
        }

        public int ExecuteSqlNonQuery(string strSQL, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        public int ExecuteProcNonQuery(string strSQL)
        {
            throw new NotImplementedException();
        }

        public int ExecuteProcNonQuery(string strSQL, System.Data.IDataParameter[] param)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
